var websocketUrl = 'ws://' + window.location.host + '/monitor/websocket';
var websocket = null;
var index = new Vue({
    el: '#all',
    data: {
        envs: []
    },
    methods: {
        getAll: function () {
            $.getJSON("../monitor/all.do", null, function(data) {
                console.log(JSON.stringify(data));
                index.envs = data;
            })
        },
        getTabHref: function (env) {
            return '#' + env;
        },
        getAppHref: function (env, app) {
            return '#' + env + '_' + app;
        }

    }
})
index.getAll();

$(function() {
    if (window['WebSocket']) {
        websocket = new WebSocket(websocketUrl);
    } else {
        websocket = new new SockJS(websocketUrl);
    }
    websocket.onopen = function(event) {
    };
    websocket.onmessage = function(event) {
        index.envs = JSON.parse(event.data);
    };
});

function heartBeat() {
    var message = {type:0};
    websocket.send(JSON.stringify(message));
    window.setTimeout("heartBeat()", 3000);
}
window.setTimeout("heartBeat()", 3000)